package db

import (
    "time"
    
)

// User 用户表模型
type User struct {
    ID             uint      `gorm:"primarykey"`
    UserName       string    `gorm:"column:user_name;type:varchar(64);uniqueIndex;not null"`
    UserPwd        string    `gorm:"column:user_pwd;type:varchar(256);not null"`
    Email          string    `gorm:"column:email;type:varchar(64)"`
    EmailValidated int       `gorm:"column:email_validated"`
    Phone          string    `gorm:"column:phone;type:varchar(128)"`
    PhoneValidated int       `gorm:"column:phone_validated"`
    SignupAt       time.Time `gorm:"column:signup_at"`
    LastActive     time.Time `gorm:"column:last_active"`
    Profile        string    `gorm:"column:profile"`
    Status         int       `gorm:"column:status;default:0"`
    AccessKey      string    `gorm:"column:AccessKey;type:varchar(128)"`
    SecretKey      string    `gorm:"column:SecretKey;type:varchar(256)"`
}

// UserFile 用户文件表模型
type UserFile struct {
    ID         uint      `gorm:"primarykey"`
    UserName   string    `gorm:"column:user_name;index;not null"`
    FileHash   string    `gorm:"column:file_sha1;index;not null"`
    FileName   string    `gorm:"column:file_name;not null"`
    FileSize   int64     `gorm:"column:file_size;not null;default:0"`
    UploadAt   time.Time `gorm:"column:upload_at"`
    LastUpdate time.Time `gorm:"column:last_update"`
    ParentPath string    `gorm:"column:parent_path;not null;default:'/'"`
    IsFolder   bool      `gorm:"column:is_folder;not null;default:false"`
    Status     int       `gorm:"column:status;not null;default:0"`
    DeletedAt  *time.Time `gorm:"column:deleted_at;index"` 
	ReferenceCount int        `gorm:"column:reference_count;not null;default:1"`
    IsOriginal     bool       `gorm:"column:is_original;not null"`
}

// File 文件表模型
type File struct {
    ID        uint      `gorm:"primarykey"`
    FileHash  string    `gorm:"column:file_sha1;type:char(40);uniqueIndex;not null"`
    FileName  string    `gorm:"column:file_name;type:varchar(256);not null"`
    FileSize  int64     `gorm:"column:file_size;not null"`
    FileAddr  string    `gorm:"column:file_addr;type:varchar(1024);not null"`
    CreateAt  time.Time `gorm:"column:create_at"`
    UpdateAt  time.Time `gorm:"column:update_at"`
    Status    int       `gorm:"column:status;default:0"`
}

// UserToken token表模型
type UserToken struct {
    ID        uint      `gorm:"primarykey"`
    UserName  string    `gorm:"column:user_name;type:varchar(64);uniqueIndex;not null"`
    Token     string    `gorm:"column:user_token;type:varchar(256);uniqueIndex;not null"`
    ExpiredAt time.Time `gorm:"column:expired_at;index"`
}

// TableName 指定表名
func (User) TableName() string {
    return "tbl_user"
}

func (UserFile) TableName() string {
    return "tbl_user_file"
}

func (File) TableName() string {
    return "tbl_file"
}

func (UserToken) TableName() string {
    return "tbl_user_token"
} 